from django.db import models
from django.contrib.auth.models import AbstractUser
from db.base_model import BaseModel


class User(AbstractUser, BaseModel):
    '''用户模型类'''
    image = models.ImageField(upload_to="", default="image/default.png", max_length=150)

    class Meta:
        db_table = 'df_user'
        verbose_name = '用户'
        verbose_name_plural = verbose_name


class Get_address:
    def get_dafult_add(self, user):
        try:
            addr = Address.objects.get(user=user)
        except Address.DoesNotExist:
            addr = None
        return addr




class Address(BaseModel):
    '''地址模型类'''
    user = models.ForeignKey('User', verbose_name='所属账户', on_delete=models.CASCADE)
    reciver = models.CharField(max_length=20, verbose_name='收货人')
    addr = models.CharField(max_length=80, verbose_name='收件地址')
    tel = models.CharField(max_length=11, verbose_name='收货电话')
    mail = models.EmailField(verbose_name='收货邮箱', blank=True)
    object = Get_address()

    class Meta:
        db_table='df_address'
        verbose_name = '收货地址'
        verbose_name_plural = verbose_name
